<?php

require_once(BaseConfig::LoadClass('cotizador.class.php'));

/**
 * Clase del cotizador que tambien presenta la funcionalidad de obtener los catalogos desde un WEB Service
 */

class CotizadorExtendido extends CotizadorSOAP {
  /**
   * @var WSSESoapClient
   */
  var $__oResCliente;
  
  function __AcoodarXMLRespuesta($strXMLRes, $bolContenidoStandard = true) {
    $strXMLRes = substr($strXMLRes, strpos($strXMLRes, "diffgr:diffgram") - 1);
    // Verificar que tenga algo el resultado (Que no venga vacio)
    $intPosSlash = strpos($strXMLRes, "/");
    $intPosGT    = strpos($strXMLRes, ">");
    if(($intPosSlash > 0) && ($intPosSlash < $intPosGT)) {
      // No hay nada en esta respuesta: Viene vacia
      return array();
    }
    $strXMLRes = substr($strXMLRes, 0, strpos($strXMLRes, "diffgr:diffgram", 2) - 2);
    $strXMLRes = substr($strXMLRes, strpos($strXMLRes, "<NewDataSet"));
    
    $strXMLRes = str_replace("diffgr:", "", $strXMLRes);
    $strXMLRes = str_replace("msdata:", "", $strXMLRes);
    
    $arrInfoDesXML = (array)simplexml_load_string($strXMLRes);
    
    if($bolContenidoStandard) {
      if(!isset($arrInfoDesXML["Table"]) && isset($arrInfoDesXML["Table1"])) {
        $arrInfoDesXML["Table"] = $arrInfoDesXML["Table1"];
      }

      $arrInfoDesXML["Table"] = (array)$arrInfoDesXML["Table"];
      if(isset($arrInfoDesXML["Table"]["@attributes"])) {
        $intIndice          = $arrInfoDesXML["Table"]["@attributes"]["rowOrder"];
        $arrRes[$intIndice] = $arrInfoDesXML["Table"];
      } else {
        $arrRes = $arrInfoDesXML["Table"];
      }
    } else {
      $arrRes = Variables::RecursiveCastToArray($arrInfoDesXML);
    }
    
    return $arrRes;
  }
  
  function ObtenerPDF($intCodCotizacion, $intCodPasado) {
    global $strGSoapNameSpace;
    global $strGSAIGImpresion;
    $strGSoapNameSpace = "http://tempuri.org/";
    
    $this->__uriMetodoConsulta = $strGSAIGImpresion;
    $strFuncion    = "ObtenerPDF";
    $arrParametros = array("idCotizacion" => "{$intCodCotizacion}/{$intCodPasado}/1", "tipo" => "1", "correodest" => "");
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    
    $strGSoapNameSpace = "";
    
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerPDF() {
    $arrRes        = array();
    
    $strXMLRes = $this->__oResCliente->__last_response;
    $strXMLRes = substr($strXMLRes, strpos($strXMLRes, "<ObtenerPDFResult"));
    $strXMLRes = substr($strXMLRes, strpos($strXMLRes, ">") + 1);
    $strXMLRes = substr($strXMLRes, 0, strpos($strXMLRes, "</ObtenerPDFResult"));
    return $strXMLRes;
  }
  
  function ObtenerCodPasado($intCodCotizacion) {
    global $strGSAIGCotizacion;
    $this->__uriMetodoConsulta = $strGSAIGCotizacion;
    $strFuncion    = "ObtenerCodPasado";
    $arrParametros = array("cod_Cotizacion" => $intCodCotizacion);
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCodPasado() {
    $arrRes        = array();
    
    $strXMLRes = $this->__oResCliente->__last_response;
    $strXMLRes = substr($strXMLRes, strpos($strXMLRes, "<ObtenerCodPasadoResult"));
    $strXMLRes = substr($strXMLRes, strpos($strXMLRes, ">") + 1);
    $strXMLRes = substr($strXMLRes, 0, strpos($strXMLRes, "</ObtenerCodPasadoResult"));
    return $strXMLRes;
  }
  
  function ObtenerCatalogoEstadoCivil() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoEstadoCivil";
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoEstadoCivil() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_edo_civil"] = $arrInfoTable["cod_est_civil"];
      $arrRes[$intIndice]["nombre"      ] = utf8_decode($arrInfoTable["txt_desc"     ]);
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function GenerarEmision($arrParametros) {
    global $strGSAIGEmision;
    $this->__uriMetodoConsulta = $strGSAIGEmision;
    $strFuncion    = "GenerarEmision";
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    
    /*
    $this->__oResCliente->__last_response = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><soap:Header><wsa:Action>http://www.chartis.com.mx/GenerarEmisionResponse</wsa:Action><wsa:MessageID>urn:uuid:1d409e1c-80e7-483a-a888-94026fdf553e</wsa:MessageID><wsa:RelatesTo>urn:uuid:f51fec9b-5150-32c2-9466-bf6fd3dc2cc9</wsa:RelatesTo><wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To><wsse:Security><wsu:Timestamp wsu:Id="Timestamp-f62ebdcd-0203-4e26-90ec-76f22a1f4bb5"><wsu:Created>2013-09-04T22:10:23Z</wsu:Created><wsu:Expires>2013-09-05T21:40:23Z</wsu:Expires></wsu:Timestamp></wsse:Security></soap:Header><soap:Body><GenerarEmisionResponse xmlns="http://tempuri.org/"><GenerarEmisionResult>https://www-400u.aig.com.mx/Impresiones_coupe/Poliza_049PAP0210262161.pdf</GenerarEmisionResult></GenerarEmisionResponse></soap:Body></soap:Envelope>';
    */
    return $this->__oResCliente;
  }
  
  function __Parse_GenerarEmision() {
    $arrRes        = array();
    
    $strXMLRes = $this->__oResCliente->__last_response;
    $strXMLRes = substr($strXMLRes, strpos($strXMLRes, "<GenerarEmisionResult"));
    $strXMLRes = substr($strXMLRes, strpos($strXMLRes, ">") + 1);
    $strXMLRes = substr($strXMLRes, 0, strpos($strXMLRes, "</GenerarEmisionResult"));
    return $strXMLRes;
  }
  
  function ObtenerCatalogoTiposUso() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoTiposUso";
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoTiposUso() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_tipo_uso" ] = $arrInfoTable["cod_Tipo_Uso"];
      $arrRes[$intIndice]["nombre"      ] = utf8_decode($arrInfoTable["txt_desc"     ]);
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoTipoPersona() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoTipoPersona";
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoTipoPersona() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_tipo_persona"] = $arrInfoTable["cod_Tipo_Persona"];
      $arrRes[$intIndice]["nombre"         ] = utf8_decode($arrInfoTable["txt_desc"     ]);
      $arrRes[$intIndice]["codigo_tabla"   ] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"          ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoProductos() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoProductos";
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoProductos() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_tipo_producto"] = $arrInfoTable["id_producto"];
      $arrRes[$intIndice]["nombre"          ] = utf8_decode($arrInfoTable["desc_reducida"]);
      $arrRes[$intIndice]["descripcion"     ] = utf8_decode($arrInfoTable["descripcion"  ]);
      $arrRes[$intIndice]["codigo_tabla"    ] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"           ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoBancos() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoBancos";
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoBancos() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_banco"       ] = $arrInfoTable["cod_banco"             ] ;
      $arrRes[$intIndice]["nombre"         ] = utf8_decode($arrInfoTable["txt_nombre"]);
      $arrRes[$intIndice]['plaza'          ] = $arrInfoTable["cod_plaza"             ] ;
      $arrRes[$intIndice]['tipo_banco'     ] = $arrInfoTable["cod_tipo_banco"        ] ;
      $arrRes[$intIndice]['status'         ] = $arrInfoTable["sn_status"             ] ;
      $arrRes[$intIndice]['max_dias_cierre'] = $arrInfoTable["max_dias_cierre_caja"  ] ;
      $arrRes[$intIndice]['desc_corta'     ] = @utf8_decode($arrInfoTable["desc_corta"]);
      $arrRes[$intIndice]["codigo_tabla"   ] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"          ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoTipoTelefono() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoTipoTelefono";
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoTipoTelefono() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_tipo_telefono"] = $arrInfoTable["cod_tipo_telef"];
      $arrRes[$intIndice]["nombre"          ] = utf8_decode($arrInfoTable["txt_desc"     ]);
      $arrRes[$intIndice]["codigo_tabla"    ] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"           ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoEstados() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoEstados";
    // Mexico es el pais 10
    $arrParametros = array("idPais" => "10", "usuarioSession" => $this->strUsername);
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoEstados() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_estado"   ] = $arrInfoTable["cod_estado" ];
      $arrRes[$intIndice]["id_pais"     ] = $arrInfoTable["cod_pais"   ];
      $arrRes[$intIndice]["nombre"      ] = utf8_decode($arrInfoTable["txt_desc"   ]);
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes"]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes"]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoMunicipios($intIdEdo) {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoMunicipios";
    // Mexico es el pais 10
    $arrParametros = array("idPais" => "10", "idEdo" => $intIdEdo);
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoMunicipios() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_municipio"] = $arrInfoTable["cod_municipio"];
      $arrRes[$intIndice]["id_estado"   ] = $arrInfoTable["cod_estado"   ];
      $arrRes[$intIndice]["id_pais"     ] = $arrInfoTable["cod_pais"     ];
      $arrRes[$intIndice]["nombre"      ] = utf8_decode($arrInfoTable     ["txt_desc"]);
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoColonias($intIdEdo, $intIdMunicipio) {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoColonias";
    // Mexico es el pais 10
    $arrParametros = array("idPais" => "10", "idEdo" => $intIdEdo, "idMun" => $intIdMunicipio);
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoColonias() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_colonia"  ] = $arrInfoTable["cod_colonia"  ];
      $arrRes[$intIndice]["id_ciudad"   ] = $arrInfoTable["cod_ciudad"   ];
      $arrRes[$intIndice]["id_municipio"] = $arrInfoTable["cod_municipio"];
      $arrRes[$intIndice]["id_estado"   ] = $arrInfoTable["cod_estado"   ];
      $arrRes[$intIndice]["id_pais"     ] = $arrInfoTable["cod_pais"     ];
      $arrRes[$intIndice]["nombre"      ] = utf8_decode($arrInfoTable     ["nombre"  ]);
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    return $arrRes;
  }
  
  function ObtenerCatalogoCiudadColonia($intIdEdo, $intIdCol, $intIdMunicipio) {
    global $strGSAIGCatalogos, $strGSAIGUser, $strGSAIGPass;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoCiudadColonia";
    // Mexico es el pais 10
    $arrParametros = array("idPais" => "10", "idEdo" => $intIdEdo, "idCol" => $intIdCol, "userName" => $strGSAIGUser, "idMun" => $intIdMunicipio);
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoCiudadColonia() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_estado"   ] = $arrInfoTable["cod_estado"   ];
      $arrRes[$intIndice]["id_ciudad"   ] = $arrInfoTable["cod_ciudad"   ];
      $arrRes[$intIndice]["nombre"      ] = utf8_decode($arrInfoTable     ["txt_desc"  ]);
      $arrRes[$intIndice]["cp"          ] = sprintf("%05d", $arrInfoTable["Column1"      ]);
      $arrRes[$intIndice]["id_colonia"  ] = $arrInfoTable["Column2"      ];
      $arrRes[$intIndice]["desc_maximo" ] = $arrInfoTable["desc_Maximo"  ];
      $arrRes[$intIndice]["no_cotiza"   ] = $arrInfoTable["no_cotiza"    ];
      
      $arrRes[$intIndice]["id_municipio"] =  0;
      $arrRes[$intIndice]["id_pais"     ] = 10;
      
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    return $arrRes;
  }
  
  function ObtenerCatalogoMarcas() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoMarcas";
    // Mexico es el pais 10
    $arrParametros = array("codunif" => "1");
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoMarcas() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_marca"    ] = $arrInfoTable["cod_marca"  ];
      $arrRes[$intIndice]["nombre"      ] = utf8_decode($arrInfoTable     ["txt_desc"]);
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerModelosMarca($intIdMarca) {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerModelosMarca";
    // Mexico es el pais 10
    $arrParametros = array("codMarca" => $intIdMarca, "codunif" => "1");
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerModelosMarca() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_modelo"   ] = $arrInfoTable["cod_modelo"];
      $arrRes[$intIndice]["nombre"      ] = utf8_decode($arrInfoTable["descripcion_larga"]);
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerAniosModelo($intIdMarca, $intIdModelo) {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerAniosModelo";
    // Mexico es el pais 10
    $arrParametros = array("codMarca" => $intIdMarca, "codModelo" => $intIdModelo);
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerAniosModelo() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["anio"        ] = $arrInfoTable["aaaa_fabrica"];
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoPaquetes() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoPaquetes";
    // Mexico es el pais 10
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoPaquetes() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_paquete"  ] = $arrInfoTable["cod_Paquete"];
      $arrRes[$intIndice]["nombre"      ] = utf8_decode($arrInfoTable["paquete"]);
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoSexo() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoSexo";
    // Mexico es el pais 10
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoSexo() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_sexo"     ] = $arrInfoTable["cod_Sexo"];
      $arrRes[$intIndice]["nombre"      ] = utf8_decode($arrInfoTable["descripcion"]);
      $arrRes[$intIndice]["codigo"      ] = utf8_decode($arrInfoTable["cod_Sexo_L"]);
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoSucursales() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoSucursales";
    // Mexico es el pais 10
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoSucursales() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_sucursal"  ] =  $arrInfoTable["cod_suc"       ];
      $arrRes[$intIndice]["nombre"       ] = utf8_decode($arrInfoTable["txt_nom_suc"]);
      $arrRes[$intIndice]["cod_tipo_dir" ] = @$arrInfoTable["cod_tipo_dir"  ];
      $arrRes[$intIndice]["cod_postal"   ] = @$arrInfoTable["nro_cod_postal"];
      $arrRes[$intIndice]["cod_colonia"  ] = @$arrInfoTable["cod_colonia"   ];
      $arrRes[$intIndice]["cod_municipio"] = @$arrInfoTable["cod_municipio" ];
      $arrRes[$intIndice]["cod_pais"     ] = @$arrInfoTable["cod_pais"      ];
      $arrRes[$intIndice]["cod_tipo_iva" ] =  $arrInfoTable["cod_tipo_iva"  ];
      $arrRes[$intIndice]["cod_ciudad"   ] = @$arrInfoTable["cod_ciudad"    ];
      $arrRes[$intIndice]["codigo_tabla" ] =  $arrInfoTable["@attributes"   ]["id"      ];
      $arrRes[$intIndice]["orden"        ] =  $arrInfoTable["@attributes"   ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoTipoDomicilio() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoTipoDomicilio";
    // Mexico es el pais 10
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoTipoDomicilio() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_tipo_dir" ] = $arrInfoTable["cod_tipo_dir"];
      $arrRes[$intIndice]["nombre"      ] = utf8_decode($arrInfoTable["txt_desc"]);
      $arrRes[$intIndice]["num_dir"     ] = $arrInfoTable["num_direc"   ];
      $arrRes[$intIndice]["codigo_tabla"] = $arrInfoTable["@attributes" ]["id"      ];
      $arrRes[$intIndice]["orden"       ] = $arrInfoTable["@attributes" ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoFormasPago() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoFormasPago";
    // Mexico es el pais 10
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoFormasPago() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_forma_pago"] = $arrInfoTable["cod_forma_pago"];
      $arrRes[$intIndice]["nombre"       ] = utf8_decode($arrInfoTable["txt_desc"]);
      $arrRes[$intIndice]["meses_dif"    ] = $arrInfoTable["cnt_dif_meses"];
      $arrRes[$intIndice]["divisor"      ] = $arrInfoTable["nro_divisor"];
      $arrRes[$intIndice]["codigo"       ] = utf8_decode($arrInfoTable["cod_lapso"]);
      $arrRes[$intIndice]["codigo_tabla" ] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"        ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCatalogoConductoPago() {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCatalogoConductoPago";
    // Mexico es el pais 10
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCatalogoConductoPago() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]["id_conducto_pago"] = $arrInfoTable["cod_conducto"];
      $arrRes[$intIndice]["nombre"          ] = utf8_decode($arrInfoTable["txt_desc_cond"]);
      $arrRes[$intIndice]["id_tipo_conducto"] = $arrInfoTable["cod_tipo_conducto"];
      $arrRes[$intIndice]["codigo_tabla"    ] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]["orden"           ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function cargaCoberturasXPaquete() {
    global $strGSAIGCatalogos;
//    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "cargaCoberturasXPaquete";
    // Mexico es el pais 10
    $arrParametros = array();
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_cargaCoberturasXPaquete() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]['id_cotizacion' ] = $arrInfoTable["cod_Cotizacion"   ];
      $arrRes[$intIndice]['id_cobertura'  ] = $arrInfoTable["cod_Cobertura"    ];
      $arrRes[$intIndice]['nombre'        ] = utf8_decode($arrInfoTable["txt_desc_cobertura"]);
      $arrRes[$intIndice]['paq_gold'      ] = $arrInfoTable["sn_Paq_Gold"      ] == "true" ? 1 : 0;
      $arrRes[$intIndice]['paq_amplio'    ] = $arrInfoTable["sn_Paq_Amplio"    ] == "true" ? 1 : 0;
      $arrRes[$intIndice]['paq_limitado'  ] = $arrInfoTable["sn_Paq_Limitado"  ] == "true" ? 1 : 0;
      $arrRes[$intIndice]['paq_basico'    ] = $arrInfoTable["sn_Paq_Basico"    ] == "true" ? 1 : 0;
      $arrRes[$intIndice]['paq_segmentado'] = $arrInfoTable["sn_Paq_Segmentado"] == "true" ? 1 : 0;
      $arrRes[$intIndice]['codigo_tabla'  ] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]['orden'         ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerDeducibles($intIdCobertura) {
    global $strGSAIGCatalogos, $strGSAIGUser, $strGSAIGPass;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerDeducibles";
    // Mexico es el pais 10
    $arrParametros = array("codUnif" => 1, "cobertura" => $intIdCobertura, "fecha" => date("Y-m-d"), "userName" => $strGSAIGUser);
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerDeducibles() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    prent_r($arrInfoDesXML);
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]['id_cotizacion' ] = $arrInfoTable["cod_Cotizacion"   ];
      $arrRes[$intIndice]['id_cobertura'  ] = $arrInfoTable["cod_Cobertura"    ];
      $arrRes[$intIndice]['nombre'        ] = utf8_decode($arrInfoTable["txt_desc_cobertura"]);
      $arrRes[$intIndice]['paq_gold'      ] = $arrInfoTable["sn_Paq_Gold"      ] == "true" ? 1 : 0;
      $arrRes[$intIndice]['paq_amplio'    ] = $arrInfoTable["sn_Paq_Amplio"    ] == "true" ? 1 : 0;
      $arrRes[$intIndice]['paq_limitado'  ] = $arrInfoTable["sn_Paq_Limitado"  ] == "true" ? 1 : 0;
      $arrRes[$intIndice]['paq_basico'    ] = $arrInfoTable["sn_Paq_Basico"    ] == "true" ? 1 : 0;
      $arrRes[$intIndice]['paq_segmentado'] = $arrInfoTable["sn_Paq_Segmentado"] == "true" ? 1 : 0;
      $arrRes[$intIndice]['codigo_tabla'  ] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]['orden'         ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerSisaModelo($intIdMarca, $intIdModelo, $intAnio) {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerSisaModelo";
    // Mexico es el pais 10
    $arrParametros = array("codMarca" => $intIdMarca, "codModelo" => $intIdModelo, "anio" => $intAnio);
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerSisaModelo() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response);
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]['id_sisa'      ] = $arrInfoTable["sisa"         ];
      $arrRes[$intIndice]['id_marca'     ] = $arrInfoTable["cod_marca"    ];
      $arrRes[$intIndice]['id_modelo'    ] = $arrInfoTable["cod_modelo"   ];
      $arrRes[$intIndice]['anio'         ] = $arrInfoTable["aaaa_fabrica" ];
      $arrRes[$intIndice]['nombre'       ] = utf8_decode($arrInfoTable["descripcion_larga"]);
      $arrRes[$intIndice]['id_moneda'    ] = $arrInfoTable["cod_moneda"   ];
      $arrRes[$intIndice]['fecha_importe'] = substr(str_replace("T", " ", $arrInfoTable["fec_importe"]), 0, 19);
      $arrRes[$intIndice]['valor_importe'] = $arrInfoTable["imp_valor"    ];
      $arrRes[$intIndice]['codigo_tabla' ] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]['orden'        ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
  
  function ObtenerCodigoAmis($intIdSISA) {
    global $strGSAIGCatalogos;
    $this->__uriMetodoConsulta = $strGSAIGCatalogos;
    $strFuncion    = "ObtenerCodigoAmis";
    $arrParametros = array("CodigoSisa" => $intIdSISA);
    $this->__oResCliente = $this->ObtenerResultadoFuncionWebService($strFuncion, $arrParametros);
    return $this->__oResCliente;
  }
  
  function __Parse_ObtenerCodigoAmis() {
    $arrRes        = array();
    
    $strXMLRes = $this->__oResCliente->__last_response;
    $strXMLRes = substr($strXMLRes, 0, strpos($strXMLRes, "/ObtenerCodigoAmisResult", 2) - 1);
    $strXMLRes = substr($strXMLRes, strpos($strXMLRes, "<ObtenerCodigoAmisResult>") + strlen("<ObtenerCodigoAmisResult>"));
    if(strtoupper(substr($strXMLRes, 0, 5)) == "ERROR") {
      return '0';
    } else {
      return $strXMLRes;
    }
  }
  
  function __Parse_GenerarCotizacion() {
    $arrRes        = array();
    $arrInfoDesXML = $this->__AcoodarXMLRespuesta($this->__oResCliente->__last_response, false);
    
    return $arrInfoDesXML;
    
    foreach($arrInfoDesXML as $intIndice => $arrInfoTable) {
      $arrInfoTable = (array)$arrInfoTable;
      $arrRes[$intIndice]['id_sisa'      ] = $arrInfoTable["sisa"         ];
      $arrRes[$intIndice]['id_marca'     ] = $arrInfoTable["cod_marca"    ];
      $arrRes[$intIndice]['id_modelo'    ] = $arrInfoTable["cod_modelo"   ];
      $arrRes[$intIndice]['anio'         ] = $arrInfoTable["aaaa_fabrica" ];
      $arrRes[$intIndice]['nombre'       ] = utf8_decode($arrInfoTable["descripcion_larga"]);
      $arrRes[$intIndice]['id_moneda'    ] = $arrInfoTable["cod_moneda"   ];
      $arrRes[$intIndice]['fecha_importe'] = substr(str_replace("T", " ", $arrInfoTable["fec_importe"]), 0, 19);
      $arrRes[$intIndice]['valor_importe'] = $arrInfoTable["imp_valor"    ];
      $arrRes[$intIndice]['codigo_tabla' ] = $arrInfoTable["@attributes"  ]["id"      ];
      $arrRes[$intIndice]['orden'        ] = $arrInfoTable["@attributes"  ]["rowOrder"];
    }
    
    return $arrRes;
  }
}

?>